package org.phantom.securityframework.api;

import java.io.Serializable;
import java.util.List;

import org.phantom.securityframework.api.Account;
import org.phantom.securityframework.api.Permission;

import org.phantom.securityframework.api.crypt.Encrypt;
import org.phantom.securityframework.api.datapermission.DataDimension;
import org.phantom.securityframework.api.domain.AccountQuery;
import org.phantom.securityframework.api.domain.Group;
import org.phantom.securityframework.api.domain.Role;
/**
 * 帐号管理接口
 * @author david
 *
 */
public interface AccountManager {

	/**
	 * 帐号状态
	 * @author david
	 *
	 */
	public enum AuthStatus{
		/**
		 * 激活
		 */
		ACTIVATION("激活", 0),
		/**
		 * 未激活
		 */
		UNACTIVATION("未激活", 1);
		
		private String name;
		private int index;
		AuthStatus(String name,int index){
			this.name = name;
			this.index = index;
		}
		public static Integer getIndex(AuthStatus status) {
	        for (AuthStatus c : AuthStatus.values()) {
	            if (c.getName().equals(status.getName())) {  
	                return c.index;  
	            }
	        }  
	        return 0;  
		}
		public static String getName(AuthStatus status) {
	        for (AuthStatus c : AuthStatus.values()) {  
	            if (c.getIndex() == status.getIndex()) {  
	                return c.name;  
	            }  
	        }  
	        return null;  
		}
		public static AuthStatus getStatus(int index){
	        for (AuthStatus c : AuthStatus.values()) {  
	            if (c.getIndex() == index) {  
	                return c;
	            }  
	        }  
	        return null;
		}
		public static AuthStatus getStatus(String name){
	        for (AuthStatus c : AuthStatus.values()) {  
	            if (c.getName().equals(name)) {  
	                return c;
	            }  
	        }  
	        return null;
		}

		private String getName() {
			return name;
		}

		public int getIndex() {
			return index;
		}

		
	}

	/**
	 * 注册帐号，状态默认为激活状态
	 * @param account
	 * @return
	 */
	Account register(Account account);
	/**
	 * 注册帐号，由客户端设置帐号状态
	 * @param account
	 * @param accountStatus
	 * @return
	 */
	Account register(Account account,AuthStatus accountStatus);
	/**
	 * 注册帐号，由客户端设置帐号状态和密码加密方式
	 * @param account
	 * @param accountStatus
	 * @return
	 * @throws Exception 
	 */
	Account register(Account account,AuthStatus accountStatus,Encrypt encrypt) throws Exception;
	/**
	 * 注册帐号，状态为激活，由客户端设置角色
	 * @param account
	 * @param roles
	 * @return
	 */
	Account registerWithRoles(Account account,Serializable[] roleIds);
	/**
	 * 注册帐号，同时由客户端设置角色和帐号状态
	 * @param account
	 * @param roles
	 * @return
	 */
	Account registerWithRoles(Account account,Serializable[] roleIds,AuthStatus accountStatus);
	Account registerWithRoles(Account account,Role[] roles);
	Account registerWithRoles(Account account,Role[] roles,AuthStatus accountStatus);
	
	
	/**
	 * 帐号注册，同时由客户端设置角色和帐号状态
	 * @param account
	 * @param groupIds
	 * @return
	 */
	Account registerWithGroups(Account account,Serializable[] groupIds);
	Account registerWithGroups(Account account,Serializable[] groupIds,AuthStatus accountStatus);
	Account registerWithGroups(Account account,Group[] groups);
	Account registerWithGroups(Account account,Group[] groups,AuthStatus accountStatus);

	
	/**
	 * 帐号注册，同时由客户端设置权限和帐号状态
	 * @param account
	 * @param groupIds
	 * @return
	 */
	Account registerWithPermissions(Account account,Serializable[] permissionIds);
	Account registerWithPermissions(Account account,Serializable[] permissionIds,AuthStatus accountStatus);
	Account registerWithPermissions(Account account,Permission[] permissions);
	Account registerWithPermissions(Account account,Permission[] permissions,AuthStatus accountStatus);
	
	/**
	 * 修改帐号
	 * @param account
	 * @return
	 */
	Account modify(Account account);
	/**
	 * 移除帐号
	 * @param account
	 * @return
	 */
	Account remove(Account account);
	Account remove(Serializable id);
	/**
	 * 激活帐号
	 * @param account
	 * @return
	 */
	Account activate(Account account);
	/**
	 * 冻结帐号
	 * @param account
	 * @return
	 */
	Account unactivate(Account account);
	/**
	 * 通过帐号序列号获取帐号
	 * @param id
	 * @return
	 */
	Account get(Serializable id);
	/**
	 * 通过帐号id获取
	 * @param accountId
	 * @return
	 */
	Account get(String accountId);
	/**
	 * 查询帐号
	 * @param props
	 * @return
	 */
	Account get(AccountQuery query);
	/**
	 * 获取帐号列表
	 * @return
	 */
	List<Account> list();
	/**
	 * 查询帐号列表
	 * @param props
	 * @return
	 */
	List<Account> list(AccountQuery query);
	
	/**
	 * 帐号总数
	 * @return
	 */
	Integer count();
	/**
	 * 条件总数
	 * @param query
	 * @return
	 */
	Integer count(AccountQuery query);
	
	void setDataDimension(Account account,DataDimension dimension);

	
}
 